package com.auction.mapper;

import com.auction.pojo.Payment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface PaymentMapper {
    /**
     * 插入支付记录
     * 
     * @param payment
     */
    @Insert("INSERT INTO payment (order_id, user_id, amount, status, payment_time, create_time, update_time) " +
            "VALUES (#{orderId}, #{userId}, #{amount}, #{status}, #{paymentTime}, #{createTime}, #{updateTime})")
    void insert(Payment payment);

    /**
     * 更新支付状态
     * 
     * @param id
     * @param status
     * @return
     */
    @Update("UPDATE payment SET status = #{status}, update_time = NOW() WHERE id = #{id}")
    int updateStatus(@Param("id") Long id, @Param("status") Integer status);

    /**
     * 根据订单ID查询支付记录
     * 
     * @param orderId
     * @return
     */
    @Select("SELECT * FROM payment WHERE order_id = #{orderId}")
    Payment selectByOrderId(@Param("orderId") Long orderId);

    /**
     * 查询用户的支付记录
     * 
     * @param userId
     * @return
     */
    @Select("SELECT * FROM payment WHERE user_id = #{userId} ORDER BY create_time DESC")
    List<Payment> selectByUserId(@Param("userId") Long userId);
}